package cn.inbot.shopadmin.module.robot.viewmodel;

import androidx.lifecycle.MutableLiveData;

import cn.inbot.shopadmin.app.AppGlobalData;
import cn.inbot.shopadmin.bean.ScanQrcodeResult;
import cn.inbot.shopadmin.module.robot.repository.ScanQrcodeRepository;
import cn.inbot.lib.framework.mvvm.java.ApiCallbackAdapter;
import cn.inbot.lib.framework.mvvm.java.PBJViewModel;
import cn.inbot.lib.network.ResponseWrapper;

/**
 * Created by shisenkun on 2021/5/11.
 */
public class ScanQrcodeViewModel extends PBJViewModel {

    private final ScanQrcodeRepository mRepository = new ScanQrcodeRepository();
    public MutableLiveData<ResponseWrapper<ScanQrcodeResult>> scanQrcodeResponseWrapper = new MutableLiveData();

    public void scanQrcode(String qrcode) {
        if (AppGlobalData.sLoginResult != null) {
            apiCall(mRepository.scanQrcode(AppGlobalData.sLoginResult.getUsername(), AppGlobalData.sLoginResult.getLoginUuid(), qrcode),
                    new ApiCallbackAdapter<ResponseWrapper<ScanQrcodeResult>>() {
                        @Override
                        public void onCompleted(ResponseWrapper<ScanQrcodeResult> responseWrapper) {
                            super.onCompleted(responseWrapper);
                            scanQrcodeResponseWrapper.setValue(responseWrapper);
                        }
                    });
        }
    }

}


